package com.txh.blog.service.impl;

import com.txh.blog.mapper.TypeMapper;
import com.txh.blog.model.Type;
import com.txh.blog.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Override
    public Map<String, Object> getTypeListPage(Integer pageNum, Integer pageSize) {
        Map<String,Object> page = new HashMap<>();
        pageNum = pageNum == null?1:pageNum;
        pageSize = pageSize == null?10:pageSize;
        int total = typeMapper.typeCount();
        List<Type> list = typeMapper.selectTypeListPage((pageNum-1)*pageSize,pageSize);
        page.put("total",total);
        page.put("list",list);
        page.put("curr",pageNum);
        return page;
    }

    @Override
    public void deleteTypeById(Long id) {
        typeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addType(Type type) {
        typeMapper.insert(type);
    }
}
